<template>
	<div class="tabs-cps-view" v-cloak>
		<div class="title">
			<div class="item">
				<div class="label">定点名称</div>
				<div class="flex-ipt-view">
					<el-input :value="prposTabelData[0] ? prposTabelData[0].posOrdr : ''" class="ipt yellow mini-ipt"
						readonly></el-input>
					<el-input :value="prposTabelData[0] ? prposTabelData[0].posName : ''" class="ipt yellow small-ipt"
						readonly style="margin-left: 8px"></el-input>
					<el-button size="mini" @click="onUpArrowClick(0)"><i class="el-icon-caret-top"></i></el-button>
					<el-button size="mini" @click="onUpArrowClick(1)"><i class="el-icon-caret-bottom"></i></el-button>
				</div>
			</div>
			<div>
				<el-button v-show="$hasEditPermission('/BHView')" size="small" :style="{
					background: $store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1 ? '#bc000f' : '',
					color: $store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1 ? 'white' : '',
					borderColor: $store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1 ? '#bc000f' : ''
				}" :type="$store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1 ? 'default' : ''"
					@click="getThckPositionInitApi">追加</el-button>
				<el-button v-show="$hasEditPermission('/BHView')" size="small" @click="DelFn"
					:disabled="$store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1"
					:type="$store.state.TH_INfo_view2Info.initType == 1 || $store.state.TH_INfo_view1Info.initType == 1 ? 'default' : ''">削除</el-button>
			</div>
		</div>
		<div class="bts-view" v-if="$hasEditPermission('/BHView')">
			<el-button size="mini" @click="sort('top')" :disabled="sortType"><i
					class="el-icon-caret-top"></i></el-button>
			<el-button size="mini" @click="sort('bottom')" :disabled="sortType"><i
					class="el-icon-caret-bottom"></i></el-button>
		</div>
		<ux-grid ref="singleTable" :data="$store.state.TH_INfo_view2Info" style="width: 100%" :header-cell-style="{
			color: 'rgba(0, 0, 0, 0.85)',
			fontSize: '14px',
			textAlign: 'left',
			fontWeight: 'bold',
			padding: 0,
			height: '32px',
		}" :cell-style="{
			color: 'rgba(96,98,102,1)',
			fontSize: '14px',
			textAlign: 'left',
			padding: 0,
			height: '32px',
		}" :row-style="{
			color: 'rgba(96,98,102,1)',
			fontSize: '13px',
			textAlign: 'left',
			padding: 0,
			height: '32px',
		}" @current-change="handleCurrentChange" highlight-current-row :height="tableHeight" v-loading="loading"
			element-loading-spinner="el-icon-loading" element-loading-background="#f8f8f8"
			:element-loading-text="$t('message.bhView.loading')">
			<template slot="empty"> No data </template>
			<ux-table-column property="msrPnt" title="方位名称" width="586">
				<template slot-scope="scope">
					<!-- <p>{{ scope.row.msrPnt }}</p> -->
					<el-input v-model="scope.row.msrPnt" class="table-input"
						@input="scope.row.msrPnt = $setMaxLength(scope.row.msrPnt, 20)" :disabled="!$hasEditPermission('/BHView')"></el-input>
				</template>
			</ux-table-column>
			<ux-table-column property="codOrdr" title="表示順位" width="86">
				<template slot-scope="scope">
					<el-input v-model="scope.row.codOrdr" class="table-input" disabled></el-input>
					<!-- <p style="text-align:center">{{ scope.row.codOrdr }}</p> -->
				</template>
			</ux-table-column>
		</ux-grid>
	</div>
</template>

<script>
import {
	getThckPosition, setThckPositionSort,
	getThckPositionInit, getDelThckPositionTipsMsg, getThckStyleTipsMsg,
	delThckPositionVerify,
	getThckStyleCombox, getThckStyle,
	updThckStyleRequiredVerify,
	updThckStyleVerify, updThckStyle, addThckVerify,
	getThckStyleInit, delThckStyle, delThckPosition
} from "@/api/api";
import $ from "jquery";
import eventBus from "@/eventBus/bus";
import _ from 'lodash-es';
import { getLocalStorage } from "../../../../utils/storage";
export default {
	name: "Tab_4",
	props: ["tableItemData", "chgDate"],

	data() {
		return {
			userData: getLocalStorage('userData'),
			prposTabelData: [],
			tableHeight: 350,
			initType: 2,
			loading: false,
			optionsValue: "",
			value: "",
			options: [],
			nowPos: 0,
			nowIndexPrpo: 0,
			sortType: false,
			selectRow: {},
			startData: []
		};
	},
	components: {},
	watch: {
		tableItemData(nVal) {
			console.log(nVal, 'VVVVVVVVVVVV');
			// 获取当前方位点的最新日期-之后再更行数据
			// this.getThckStyleComboxApi();
			// setTimeout(() => {
			if (nVal == 'no Data') {
				this.prposTabelData = [];
				this.$store.state.TH_INfo_view1Info = {};
				this.$store.state.TH_INfo_view2Info = [];
			} else {
				this.getThckPositionApi();
			}
			// }, 300);
		},
		"$store.state.TH_INfo_view2Info": {
			handler(nVal) {
				console.log('sfsdfsdf 231', nVal, this.prposTabelData);

				// if (nVal.length != this.prposTabelData.length) {
				// 	this.$emit("DataChangeFn", !false);
				// 	return
				// }
				setTimeout(() => {
					nVal.forEach((item, index) => {
						this.prposTabelData[index]._XID = item._XID;
					})
					this.$emit("DataChangeFn", !_.isEqual(nVal, this.prposTabelData));
				}, 500);

			},
			deep: true,
		},
		'$store.state.isStop.name': function (nVal, oVal) {
			//你需要执行的代码
			console.log(nVal, oVal);
			// if (nVal == 'active') {
			// 	this.initFn();
			// }
		},
	},
	computed: {
	},
	methods: {
		//保存
		async initFn() {
			let view1DataJson = this.$store.state.TH_INfo_view1Info;
			let ThckSArr = [
				{ title: '建設年月', val: view1DataJson.chgDate },
				{ title: '定点名称', val: view1DataJson.ttpPosOrdr },
				{ title: '定点No', val: view1DataJson.ttpPosOrdr },
				{ title: '元肉厚', val: view1DataJson.orgThck },
				{ title: '管理値', val: view1DataJson.mgtThck },
				{ title: 'ラインNo', val: view1DataJson.macCode }
			];
			//1.获取保存提示
			let msg = await this.getThckStyleTipsMsgApi();
			this.$confirm(msg, '', {
				confirmButtonText: 'OK',
				cancelButtonText: 'Cancel',
				type: 'warning'
			}).then(async () => {
				console.log(111111);
				//2.验证必填项lab
				let msg_lab = '';
				let k = this.$store.state.macType == 1 ? 1 : 0;
				for (let i = 0; i < ThckSArr.length - k; i++) {
					if (ThckSArr[i].val == '') {
						msg_lab = await this.updThckStyleRequiredVerifyApi(ThckSArr[i].title);
					}
				}
				if (msg_lab != '') {
					this.$alert(msg_lab, '', {
						confirmButtonText: 'OK',
						type: 'warning',
						callback: action => { }
					});
					return
				}
				console.log(2222222222);
				//3.更新前验证
				let updRes = await this.updThckStyleVerifyApi();

				if (updRes.data.code == 0) {
					this.$alert(updRes.data.msg, '', {
						confirmButtonText: 'OK',
						type: 'warning',
						callback: action => {
						}
					});
					return
				}
				console.log(33333333);

				if (updRes.data.code == 451) {
					this.$confirm(updRes.data.msg, '', {
						confirmButtonText: 'OK',
						cancelButtonText: 'Cancel',
						type: 'warning'
					}).then(async () => {
						//4调用更新
						let upRes = await this.updThckStyleApi();
						if (upRes.data.code != 0) {
							this.$message({
								type: 'error',
								message: upRes.data.msg
							});
							return
						}
						this.$message({
							type: 'success',
							message: 'OK'
						});
						this.$store.commit('reSetIsStop');
						eventBus.$emit('goNextOfLeftTable');
						// eventBus.$emit('goNextOfCenterTable');
						eventBus.$emit('LoadTabelData');
						this.getThckPositionApi();
					}).catch(() => {

					});
					return
				}
				//4调用更新=>更新底层表格
				let upRes = await this.updThckStyleApi();
				if (upRes.data.code != 0) {
					this.$message({
						type: 'error',
						message: upRes.data.msg
					});
					return
				}
				this.$store.commit('reSetIsStop');
				eventBus.$emit('goNextOfLeftTable');
				// eventBus.$emit('goNextOfCenterTable');
				eventBus.$emit('LoadTabelData');
				this.getThckPositionApi();
				this.$message({
					type: 'success',
					message: 'OK'
				});

			}).catch(() => {
				this.$store.commit('reSetIsStop');
				eventBus.$emit('goNextOfLeftTable');
				eventBus.$emit('goNextOfCenterTable');
				// eventBus.$emit('LoadTabelData');
				// this.getThckPositionApi();
			});
		},
		//削除
		async DelFn() {
			let delRes = await this.getDelThckPositionTipsMsgApi();
			// let delRes = '123'
			this.$confirm(delRes, '', {
				confirmButtonText: 'OK',
				cancelButtonText: 'Cancel',
				type: 'warning'
			}).then(async () => {
				let oneRes = await this.delThckPositionVerifyApi();
				if (oneRes.data.code == 0) {
					this.$alert(oneRes.data.msg, '', {
						confirmButtonText: 'OK',
						type: 'warning',
						callback: action => {
						}
					});
					return
				}
				console.log(111111111);
				let twoRes = await this.delThckPositionApi();
				console.log(twoRes);
				if (twoRes.data.code != 0) {
					this.$message({
						type: 'error',
						message: twoRes.data.msg
					});
					return
				}
				console.log(22222222);
				this.getThckPositionApi();
				eventBus.$emit('LoadTabelData');

				this.$message({
					type: 'success',
					message: twoRes.data.msg
				});
			}).catch(() => {

			});
		},
		//削除
		async delThckPositionApi() {
			let dataJson = {
				AddType: false,//是	bool	true or false 追加标识
				MsrPnt: this.selectRow.msrPnt.toString(),//是	string	方位名称
				DmgCode: Number(this.tableItemData.DMG_CODE),//是	int	设备编号
				PosNo: this.selectRow.posNo.toString(),//是	string	位置No 54
				ClsType: Number(this.selectRow.clsType),//是	int	方位番号 58
				ThckPositionLst: [
					this.selectRow
				],
			}
			console.log(dataJson);
			let res
			try {
				res = await delThckPosition(dataJson);

			} catch (error) {
				console.log(error);
			}
			return res
		},
		//削除前验证
		async delThckPositionVerifyApi() {
			let dataJson = {
				AddType: false,//是	bool	true or false 追加标识
				MsrPnt: this.tableItemData.MSR_PNT.toString(),//是	string	方位名称
				DmgCode: Number(this.tableItemData.DMG_CODE),//是	int	设备编号
				PosNo: this.selectRow.posNo.toString(),//是	string	位置No 54
				ClsType: Number(this.selectRow.clsType),//是	int	方位番号 58
				ThckPositionLst: [
					this.selectRow
				],
			}
			console.log(dataJson);

			let res = await delThckPositionVerify(dataJson);
			return res
		},
		//获取削除提示
		async getDelThckPositionTipsMsgApi() {
			let res = await getDelThckPositionTipsMsg({ MsrPnt: this.selectRow.msrPnt.toString() });
			return res.data.msg
		},
		//1获取 肉厚仕样 提示信息 1 削除和更新都用这个 接口2
		async getThckStyleTipsMsgApi(type = 1, addType = false) {
			let dataJosn = {
				type,
				ttpPosOrdr: this.prposTabelData[0].posOrdr.toString(),
				addType,
			};
			let res = await getThckStyleTipsMsg(dataJosn);
			return res.data.msg
		},
		//2必填项的验证
		async updThckStyleRequiredVerifyApi(lab) {
			let dataJosn = {
				lab
			};
			let res = await updThckStyleRequiredVerify(dataJosn);
			return res.data.msg
		},
		//3.更新前验证
		getDataJson() {
			debugger
			let view2DataJson = this.prposTabelData;
			let view1DataJson = this.$store.state.TH_INfo_view1Info;

			let ThckPositionLst = [];
			view2DataJson.forEach(item => {
				ThckPositionLst.push(
					{
						PosOrdr: item.posOrdr,//是	int	PosOrdr
						PosName: view1DataJson.ttpPosOrdr.toString(),//是	string	PosName
						CodOrdr: Number(item.codOrdr),//是	int	表示順
						MsrPnt: item.msrPnt,//是	string	方位名称
						PosNo: item.posNo,//是	int	PosNo
						RevNo: item.revNo,//是	int	RevNo
						ClsType: item.clsType,//是	int	ClsType
					}
				)
			});

			let dataJosn = {
				PltCode: Number(this.$store.state.pltCode),//是	int	装置ID
				DmgCode: this.$store.state.macCode,//是	int	设备编号
				ThckStyleType: 2,//是	int	肉厚仕样类型 1=追加 2=更新
				PositionType: this.initType,//是	int	肉厚方位类型 1=追加 2=更新
				ChgDate: view1DataJson.chgDate,//是	string	建设年月 1
				PosOrdr: Number(view1DataJson.ttpPosOrdr),//是	int	位置順 2
				OldPosOrdr: Number(view1DataJson.OldPosOrdr),//是	int	原始位置順
				PosName: view1DataJson.posName.toString(),//是	string	定点名称 3
				UseCase: view1DataJson.useCase ? view1DataJson.useCase.toString() : '',//是	string	利用状況 運用中：1、休止中：2 4
				GrnPosNo: Number(view1DataJson.ttgPosOrdr),//是	int	グループ番号 没有输入: view1DataJson.posCode则,//是0 5
				OrgThck: view1DataJson.orgThck ? view1DataJson.orgThck.toString() : '',//是	string	元肉厚 9
				MgtThck: view1DataJson.mgtThck ? view1DataJson.mgtThck.toString() : '',//是	string	管理値 10
				LmtThck: view1DataJson.lmtThck ? view1DataJson.lmtThck.toString() : '',//是	string	限界値 11
				CrrThck: view1DataJson.crrThck ? view1DataJson.crrThck.toString() : '',//是	string	腐れ代 12
				MtrClsCode: view1DataJson.mtrClsCode ? view1DataJson.mtrClsCode.toString() : '',//是	string	材質 13
				MtrName: view1DataJson.mtrName ? view1DataJson.mtrName.toString() : '',//是	string	材質名称 14
				SizCode: view1DataJson.sizCode ? view1DataJson.sizCode.toString() : '',//是	string	サイズ 15
				SchCode: view1DataJson.schCode ? view1DataJson.schCode.toString() : '',//是	string	Ｓｃｈ 16
				CorLoop: view1DataJson.corLoopCode.toString(),//是	string	CL番号 17
				// CorLoop: '0',//是	string	CL番号 17
				MacCode: view1DataJson.macCode ? view1DataJson.macCode.toString() : '',//是	string	機器コード 18
				CrrType: Number(view1DataJson.crrType) == 0 ? 0 : Number(view1DataJson.crrType) || -1,//是	int	更新直後の腐食率の適用ルール 更新前の値:0、ループ内最大値:1、手入力:2 19

				StaCrr: view1DataJson.staCrr ? view1DataJson.staCrr.toString() : '',//是	string	手入力 20
				PosCode: Number(view1DataJson.posCode),//是	int	測定部位 21
				ThkTypCode: Number(view1DataJson.thkTypCode),//是	int	保温保冷 22
				IcdCstCode: Number(view1DataJson.icdCstCode),//是	int	足場工事 23
				IspWayType: Number(view1DataJson.ispWayType),//是	int	検査方法 24
				LifeCnt: view1DataJson.lifeCnt ? view1DataJson.lifeCnt.toString() : '',//是	string	周期設定係数 25
				LifeMax: view1DataJson.lifeMax ? view1DataJson.lifeMax.toString() : '',//是	string	最長検査周期 26
				Height: view1DataJson.height ? view1DataJson.height.toString() : '',//是	string	高さ 27
				FlmCnt: view1DataJson.flmCnt ? view1DataJson.flmCnt.toString() : '',//是	string	ﾌｨﾙﾑ枚数 28
				Option01: view1DataJson.option01 ? '1' : '0',//是	string	自主保安 29
				Option02: view1DataJson.option02 ? '1' : '0',//是	string	監視点 30
				Option03: view1DataJson.option03 ? '1' : '0',//是	string	移動点 31
				Option04: view1DataJson.option04 ? '1' : '0',//是	string	非定例 32
				Option05: view1DataJson.option05 ? '1' : '0',//是	string	定点 33
				Option06: view1DataJson.option06 ? '1' : '0',//是	string	機器ノズル 34
				Option07: view1DataJson.option07 ? '1' : '0',//是	string	スタンドパイプ 35
				Option08: view1DataJson.option08 ? '1' : '0',//是	string	ｵﾌﾟｼｮﾝﾌﾗｸﾞ08 36
				Option09: view1DataJson.option09 ? '1' : '0',//是	string	ｵﾌﾟｼｮﾝﾌﾗｸﾞ09 37
				Option10: view1DataJson.option10 ? '1' : '0',//是	string	ｵﾌﾟｼｮﾝﾌﾗｸﾞ10 38
				// Search01: view1DataJson.f1Name ? view1DataJson.f1Name.toString() : '',//是	string	検索用ワード01 39
				// Search02: view1DataJson.f2Name ? view1DataJson.f2Name.toString() : '',//是	string	検索用ワード02 40
				// Search03: view1DataJson.f3Name ? view1DataJson.f3Name.toString() : '',//是	string	検索用ワード03 41
				// Search04: view1DataJson.f4Name ? view1DataJson.f4Name.toString() : '',//是	string	検索用ワード04 42
				// Search05: view1DataJson.f5Name ? view1DataJson.f5Name.toString() : '',//是	string	検索用ワード05 43

				Search01: view1DataJson.f1Code.toString(),//是	string	検索用ワード01 39
				Search02: view1DataJson.f2Code.toString(),//是	string	検索用ワード01 39
				Search03: view1DataJson.f3Code.toString(),//是	string	検索用ワード01 39
				Search04: view1DataJson.f4Code.toString(),//是	string	検索用ワード01 39
				Search05: view1DataJson.f5Code.toString(),//是	string	検索用ワード01 39


				Note: view1DataJson.note ? view1DataJson.note.toString() : '',//是	string	特記事項 44
				UpdUser: 'admin',//是	string	更新者

				PosNo: Number(view1DataJson.posNo),//是	int	位置No 54
				RevNo: Number(view1DataJson.revNo),//是	int	リビジョンNo 55
				ThckPositionLst//是	List<T>	方位信息 集合
			};
			console.log(dataJosn, 'dddd');
			return dataJosn;
		},
		async updThckStyleVerifyApi() {
			let res = await updThckStyleVerify(this.getDataJson());
			return res;
		},
		//4调用更新
		async updThckStyleApi() {
			let res = await updThckStyle(this.getDataJson());
			return res;
		},



		// 切换球标
		onUpArrowClick(inAct) {
			//初始监听状态
			if (!this.rightResultViewFlag) {
				eventBus.$emit('getBasicStyleCompontensCurrent_EventBus');	//	基本仕样
			}

			let Fn = () => {
				//新添加验证是否修改，是否可以跳转=》如果修改先提示保存之后可以跳转
				if (this.$store.state.isStop.flg) {
					this.initFn();
					return
				}

				// this.prposTabelData = [];
				// this.$emit("onChangeSelectClick", inAct)
				console.log("onUpArrowClick  --- ", inAct)
				eventBus.$emit("onChangeSelectClick", inAct);
			}
			/**
			 * 2。  记录当前函数。
			 */
			if (this.$store.state.isCurrentNext) {
				Fn();
			} else {
				/**
				  * 4-1。   记录原来该运行的函数。
				  * 4-2。   执行保存弹出框操作。   
				  */
				this.$store.commit("changeIsCurrentFn", Fn);

				eventBus.$emit('EventBusBasicStyleCompontensSaveFn');	//	基本仕样
			}


		},
		changeIndex(array, index1, index2) {
			[array[index1], array[index2]] = [array[index2], array[index1]];
		},
		// 上下位置切换
		sort(position) {
			if (this.nowIndexPrpo == -1) return;
			console.log(this.nowIndexPrpo);
			if (position === "top") {
				if (this.nowIndexPrpo <= 0) return;
				this.changeIndex(this.$store.state.TH_INfo_view2Info, this.nowIndexPrpo, this.nowIndexPrpo - 1);
				this.nowIndexPrpo--;
				// this.setThckPositionSortApi(this.$store.state.macCode, Number(this.tableItemData.POS_NO), this.$store.state.TH_INfo_view1Info.chgDate, this.prposTabelData[this.nowIndexPrpo].codOrdr, this.prposTabelData[this.nowIndexPrpo - 1].codOrdr, "top");
			} else if (position === "bottom") {
				if (this.nowIndexPrpo >= this.$store.state.TH_INfo_view2Info.length - 1) return;
				this.changeIndex(this.$store.state.TH_INfo_view2Info, this.nowIndexPrpo, this.nowIndexPrpo + 1)
				this.nowIndexPrpo++;
				// this.setThckPositionSortApi(this.$store.state.macCode, Number(this.tableItemData.POS_NO), this.$store.state.TH_INfo_view1Info.chgDate, this.prposTabelData[this.nowIndexPrpo].codOrdr, this.prposTabelData[this.nowIndexPrpo + 1].codOrdr, "bottom");
			}
			console.log(this.$store.state.TH_INfo_view2Info);
			this.$set(this.$store.state.TH_INfo_view2Info, this.nowIndexPrpo, this.$store.state.TH_INfo_view2Info[this.nowIndexPrpo])
		},

		setThckPositionSortApi(DmgCode, PosNo, chgDate, FromCodOrdr, ToCodOrdr, move) {
			let dataJosn = {
				DmgCode,
				PosNo,
				chgDate,
				FromCodOrdr,
				ToCodOrdr,
			};
			setThckPositionSort(dataJosn)
				.then((res) => {
					console.log(res, 'setDataSortApi');
					if (res.data.code != 0) {
						return;
					}
					this.getThckPositionApi();

					if (move == "top") {
						this.nowIndexPrpo--;
					} else if (move == "bottom") {
						this.nowIndexPrpo++;
					}

				})
				.catch(() => { })
				.finally(() => { }
				);
		},
		handleCurrentChange(val) {

			this.selectRow = val;
			console.log(val, this.prposTabelData);
			this.$store.state.TH_INfo_view2Info.forEach((i, v) => {
				if (i.codOrdr == val.codOrdr) this.nowIndexPrpo = v;
			});
			// this.sortType = false;
		},

		// 获取当前方位点的最新日期
		async getThckStyleComboxApi() {
			let res = await getThckStyleCombox({
				dmgCode: this.$store.state.macCode,
				MacCode: this.$store.state.macCode,
				posNo: Number(this.tableItemData.POS_NO),
				macType: this.$store.state.macType,
			})
			if (res.data.code != 0) {
				return;
			}
			this.$store.state.TH_INfo_viewComboxList = res.data.data;
			return res.data.data.chgDate[0].label;
		},

		//获取数据=》view1
		async getThckStyleApi() {

			let chgDate = await this.getThckStyleComboxApi();
			let res = await getThckStyle({
				dmgCode: this.$store.state.macCode,
				posNo: Number(this.tableItemData.POS_NO) || 0,
				chgDate,
			})
			console.log("getThckStyleApi", res);
			if (res.data.code == 0 && res.data.data.length > 0) {
				this.resultData = res.data.data[0];

				this.resultData.crrThck = this.resultData.crrThck ? this.resultData.crrThck : '';
				this.resultData.corLoopCode = this.resultData.corLoopCode.toString();
				this.resultData.f1Code = this.resultData.f1Code.toString();
				this.resultData.f2Code = this.resultData.f2Code.toString();
				this.resultData.f3Code = this.resultData.f3Code.toString();
				this.resultData.f4Code = this.resultData.f4Code.toString();
				this.resultData.f5Code = this.resultData.f5Code.toString();
				this.resultData.option01 = this.resultData.option01 == 1 ? true : false;
				this.resultData.option02 = this.resultData.option02 == 1 ? true : false;
				this.resultData.option03 = this.resultData.option03 == 1 ? true : false;
				this.resultData.option04 = this.resultData.option04 == 1 ? true : false;
				this.resultData.option05 = this.resultData.option05 == 1 ? true : false;
				this.resultData.option06 = this.resultData.option06 == 1 ? true : false;
				this.resultData.option07 = this.resultData.option07 == 1 ? true : false;
				this.resultData.option08 = this.resultData.option08 == 1 ? true : false;
				this.resultData.option09 = this.resultData.option09 == 1 ? true : false;
				this.resultData.option10 = this.resultData.option10 == 1 ? true : false;
				this.resultData.OldPosOrdr = this.resultData.ttpPosOrdr;


				this.$store.state.TH_INfo_view1Info = this.resultData;
				return
			}
			if (res.data.code == -300) {


				return
			}
			this.$message({
				type: 'error',
				message: res.data.msg
			})

		},
		//获取数据=》view2
		async getThckPositionApi() {

			this.getThckStyleApi();
			this.initType = 2;
			this.chgDate = await this.getThckStyleComboxApi();
			this.prposTabelData = [];
			return getThckPosition({
				dmgCode: this.$store.state.macCode,
				posNo: Number(this.tableItemData.POS_NO) || 0,
				chgDate: this.chgDate,
			}).then((res) => {
				console.log("getThckPositionApi", res);
				if (res.data.data) {
					this.prposTabelData = res.data.data;
					this.prposTabelData.sort((a, b) => {
						return a.codOrdr - b.codOrdr;
					})
					this.startData = _.cloneDeep(this.prposTabelData);

					this.$store.state.TH_INfo_view2Info = this.prposTabelData;

					this.$store.state.TH_INfo_view2Info.forEach((item, index) => {
						this.prposTabelData[index]._XID = item._XID;
					})
					// 获取到数据加载高亮
					if (this.nowIndexPrpo >= this.prposTabelData.length) {
						this.nowIndexPrpo = this.prposTabelData.length - 1
					}
					this.$refs.singleTable.setCurrentRow(this.prposTabelData[this.nowIndexPrpo]);
					this.selectRow = this.prposTabelData[this.nowIndexPrpo]
				}
			});
		},

		async getThckPositionInitApi() {
			await this.getThckPositionApi();
			let dataJson = {
				dmgCode: this.$store.state.macCode,
				posNo: Number(this.tableItemData.POS_NO) || 0,
				chgDate: this.chgDate,
			}
			let res = await getThckPositionInit(dataJson);
			let temp = res.data.data;
			temp.codOrdr = this.prposTabelData[this.prposTabelData.length - 1].codOrdr + 1
			this.prposTabelData.push(temp);
			this.$store.state.TH_INfo_view2Info = this.prposTabelData;
			this.initType = 1;

			this.$store.state.TH_INfo_view2Info.initType = 1;
		},
		resizeHeightFn() {
			let heightStyle = $(".tabs-cps-view").height() - 10;
			this.tableHeight = heightStyle > 500 ? 482 : heightStyle;
		}
	},

	created() {
		let that = this;
		// this.$nextTick(function () {
		// 	let heightStyle = $(".tabs-cps-view").height() - 10;
		// 	that.tableHeight = heightStyle;
		// });
	},
	mounted() {
		if (this.$store.state.TH_INfo_view2Info.initType == 1 || this.$store.state.TH_INfo_view1Info.initType == 1) {
			this.initType = 1
		} else {
			this.initType = 2
		}
		if (Object.keys(this.$store.state.TH_INfo_view1Info).length <= 1) {
			this.getThckStyleComboxApi();
		} else {
			this.prposTabelData = this.$store.state.TH_INfo_view2Info;
		}

		window.addEventListener(
			"resize",
			() => {
				return (() => {
					let heightStyle = $(".tabs-cps-view").height() - 10;
					this.tableHeight = heightStyle;
				})();
			},
			false
		);

		// 如果缓存中有此数据，即拿到，否则重新请求=》注意存入缓存和清除内容
		this.prposTabelData = this.$store.state.TH_INfo_view2Info;
		this.$refs.singleTable.setCurrentRow(this.prposTabelData[this.nowIndexPrpo]);
		this.startData = _.cloneDeep(this.prposTabelData);


		setTimeout(() => {
			this.$refs.singleTable.setCurrentRow(this.prposTabelData[0]);
			this.selectRow = this.prposTabelData[0]
		}, 300);

		console.log(this.prposTabelData);

		eventBus.$on("clearTwo", (e) => {
			this.prposTabelData.length = 0
			this.prposTabelData = e;
			this.$store.state.TH_INfo_view2Info = e;
		})

	},
	beforeDestroy() {
		this.$store.state.TH_INfo_view2Info.initType = this.initType;

		eventBus.$off('clearTwo')
	},
	destroyed() { },
};
</script>
<style lang="scss" scoped>
[v-cloak] {
	display: none;
}

.tabs-cps-view {
	width: 100%;

	.title {
		width: 100%;
		height: 32px;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 12px;

		::v-deep .el-button+.el-button {
			// background: #fff;
		}

		.add-btn {
			height: 32px;
			background: #106ebe;
			color: #fff;
			border-radius: 4px;
		}

		.item {
			// width: 48%;
			display: flex;
			justify-content: flex-start;

			.label {
				width: 70px;
				display: flex;
				align-items: center;
			}

			.strat-view {
				width: calc(100% - 89px);
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
		}

		.flex-ipt-view {
			width: 340px;
			height: 32px;
			display: flex;
			align-items: center;
			justify-content: flex-start;

			button {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 32px;
				max-width: 32px;
				height: 32px;
				// border: 1px solid #d9d9d9;
				margin-left: 8px;
				// border-radius: 4px;
				font-size: 18px;
			}
		}

		.ipt {
			width: 238px;
			height: 32px;

			::v-deep .el-input__inner {
				width: 238px;
				height: 32px;
			}

			::v-deep .el-input__inner:focus {
				border: 1px solid #dcdfe6;
			}

			::v-deep .el-input__icon {
				line-height: 32px;
				color: #909399;
			}

			::v-deep .el-input__suffix {
				width: 32px;
				right: 0;
				background: #dee0e3;
			}
		}

		.small-ipt {
			width: 180px;

			::v-deep .el-input__inner {
				width: 100%;
				height: 32px;
			}
		}

		.mini-ipt {
			width: 48px;

			::v-deep .el-input__inner {
				width: 100%;
				height: 32px;
				padding: 0;
				text-align: center;
			}
		}

		.yellow {
			::v-deep .el-input__inner {
				background: #ceedf4;
			}
		}
	}

	.bts-view {
		text-align: right;
		margin-bottom: 10px;
		display: flex;
		justify-content: flex-end;
		// button {
		// 	width: 32px;
		// 	height: 32px;
		// 	// border: 1px solid #d9d9d9;
		// 	margin-left: 8px;
		// 	// border-radius: 4px;
		// 	font-size: 18px;
		// }

		button {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 32px;
			max-width: 32px;
			height: 32px;
			// border: 1px solid #d9d9d9;
			margin-left: 8px;
			// border-radius: 4px;
			font-size: 18px;
		}
	}
}

.table-input {
	::v-deep .el-input__inner {
		background: none;
		border: 0 none;
		padding: 0;
	}
}
</style>
